package demo;
class SingletonLazy {
    private static volatile SingletonLazy instance = null;//一开始不初始化对象
    private static Object locker = new Object();
    public static SingletonLazy getInstance() {//什么时候调用，才会初始化对象
        if(instance == null) {
            synchronized (locker) {
                if(instance == null) {
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }
    private SingletonLazy() {

    }
}
public class Test2 {
    public static void main(String[] args) {
        SingletonLazy s1  = SingletonLazy.getInstance();
        SingletonLazy s2  = SingletonLazy.getInstance();
        System.out.println(s1 == s2);
    }
}
